package cn.itsource.ymcc.consumer;

import cn.itsource.ymcc.constant.Constants;
import cn.itsource.ymcc.constant.CourseConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RocketMQMessageListener(
        consumerGroup = "SmsConsumer",//消费者组名
        topic = CourseConstants.TOPIC_COURSE_MESSAGE_SMS,
        selectorExpression = CourseConstants.TAGS_COURSE_MESSAGE_SMS
)
public class CourseMessageSmsConsumer  implements RocketMQListener<MessageExt> {
    @Override
    public void onMessage(MessageExt messageExt) {
        try {
            byte[] body = messageExt.getBody();
            String message = new String(body, Constants.UTF8);
            System.out.println(message);
        } catch (Exception e){
            log.error(e.getMessage());
            e.printStackTrace();
        }
    }
}
